package com.zyg.controller;

import com.zyg.model.Result;
import com.zyg.model.param.SysUserParam;
import com.zyg.model.query.SysUserQueryParam;
import com.zyg.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/va/user")
@RestController
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户登录
     * @param loginName 登录账号
     * @param passWord 登录密码
     * @return
     */
    @PostMapping("/login")
    public Result userLogin(@RequestParam String loginName,@RequestParam String passWord){
        return sysUserService.userLogin(loginName,passWord);
    }

    /**
     * 刷新用户的token
     */
    @GetMapping("/refresh-token")
    public Result refreshUserToken(){
        return sysUserService.refreshUserToken();
    }

    /**
     * 退出登录
     * @return
     */
    @PostMapping("/out-login")
    public Result userOutLogin(){
        return sysUserService.userOutLogin();
    }

    /**
     * 分页获取数据
     * @param queryParam
     * @return
     */
    @GetMapping("/page")
    public Result getUserPageList(@Validated SysUserQueryParam queryParam){
        return sysUserService.getUserPageList(queryParam);
    }

    /**
     * 通过id获取用户详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getUserById(@PathVariable String id){
        return sysUserService.getUserById(id);
    }

    /**
     * 添加用户
     * @param user 用户信息
     * @return
     */
    @PostMapping
    public Result userAdd(SysUserParam user){
        return sysUserService.userAdd(user);
    }

    /**
     * 更新用户信息
     * @param userParam
     * @return
     */
    @PutMapping
    public Result updateUser(SysUserParam userParam){
        return sysUserService.updateUser(userParam);
    }

    @DeleteMapping("/{id}")
    public Result deleteUserById(@PathVariable String id){
        return sysUserService.deleteUserById(id);
    }
}
